from rest_framework import serializers

from rest_framework.validators import UniqueValidator
from rest_framework.validators import UniqueTogetherValidator

from student.models import Student
from school.serializers import SchoolListSerializer
from rest_framework.compat import unicode_to_repr

class StudentListSerializer(serializers.ModelSerializer):
    """
    学员详情序列化类
    """
    gender = serializers.SerializerMethodField()
    payment_status = serializers.SerializerMethodField()
    school = SchoolListSerializer()
    registration_date = serializers.DateTimeField(format('%Y-%m-%d %H:%M'), help_text='报名日期', label='报名日期')
    create_time = serializers.DateTimeField(format('%Y-%m-%d %H:%M'), help_text='报名日期', label='报名日期')

    class Meta:
        model = Student
        fields = "__all__"

    def get_gender(self, obj):
        data = {
            'key':str(obj.gender),
            'value':obj.get_gender_display()
        }
        return data

    def get_payment_status(self, obj):
        data = {
            'key':str(obj.payment_status),
            'value':obj.get_payment_status_display()
        }
        return data




class StudentCreateSerializer(serializers.ModelSerializer):
    """
    学员新建序列化类
    """
    ID_number = serializers.CharField(label="身份证号", help_text="身份证号",
                                     required=True, allow_blank=False,
                                     validators=
                                     [UniqueValidator(queryset=Student.objects.all(), message="学生已经存在")])
    class Meta:
        model = Student
        exclude = ['create_time']


class StudentGroupingSerializer(serializers.Serializer):
    # group_num =serializers.SerializerMethodField()
    # match_date =serializers.SerializerMethodField()
    # age = serializers.SerializerMethodField()
    # class Meta:
    #     model = Student
    #     fields = ['group_num','match_date','age']
    #
    # def get_group_num(self,obj):
    pass

